using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Windows.Forms;

namespace GotLyrics
{
    class AudioFileListViewItemSorter : IComparer
    {
        private int _column;
        /// <summary>
        /// Gets or sets the column.
        /// </summary>
        /// <value>The column.</value>
        public int Column
        {
            get { return _column; }
            set { _column = value; }
        }

        private ListView _listView;
        /// <summary>
        /// Gets or sets the list view.
        /// </summary>
        /// <value>The list view.</value>
        public ListView ListView
        {
            get { return _listView; }
            set 
            { 
                if(_listView != null)
                    _listView.ColumnClick -= new ColumnClickEventHandler(ListViewColumnClick);

                _listView = value; 

                if(_listView != null)
                    _listView.ColumnClick += new ColumnClickEventHandler(ListViewColumnClick);
            }
        }

        void ListViewColumnClick(object sender, ColumnClickEventArgs e)
        {
            //Type t = typeof(this); 
        }
	

        public AudioFileListViewItemSorter(ListView listView)
        {
            ListView = listView;
        }

        /// <summary>
        /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other.
        /// </summary>
        /// <param name="x">The first object to compare.</param>
        /// <param name="y">The second object to compare.</param>
        /// <returns>
        /// Value Condition Less than zero x is less than y. Zero x equals y. Greater than zero x is greater than y.
        /// </returns>
        /// <exception cref="T:System.ArgumentException">Neither x nor y implements the <see cref="T:System.IComparable"></see> interface.-or- x and y are of different types and neither one can handle comparisons with the other. </exception>
        public int Compare(object x, object y)
        {
            ListViewItem xItem = (ListViewItem)x;
            ListViewItem yItem = (ListViewItem)y;
            
            string xText = xItem.SubItems[Column].Text;
            string yText = yItem.SubItems[Column].Text;

            
            return String.Compare(xText, yText);
        }
    }
}
